﻿Imports System.Data.SqlClient
Imports System.Data

Partial Class service_driver_availability
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        'Make sure it's not the admin
        If Session("driver_id") Is Nothing Then
            Session("loggedin") = False
            Response.Redirect("default.aspx")
        End If

        CSSADB_Availability.SelectCommand = "SELECT * FROM [driver_availability] where driverID=" & Session("driver_ID") & " ORDER BY case [Day] when 'Monday' then 1 when 'Tuesday' then 2 when 'Wednesday' then 3 when 'Thursday' then 4 when 'Friday' then 5 when 'Saturday' then 6 when 'Sunday' then 7 else 8 end"

    End Sub

    'Private Const ConnectionString As String = "Data Source=sql2008.campus.jcu.edu ; Initial Catalog=service; User Id=Thunder48; Password=Thundertech169;"


    Protected Sub submitButton_Click(sender As Object, e As EventArgs) Handles submitButton.Click

        Try
            Dim conn As New SqlConnection
            Dim cmd As String
            Dim sql As SqlCommand = New SqlCommand
            Dim day As String
            Dim startTime As Date
            Dim endTime As Date
            Dim driverInfo As driverInfo = New driverInfo()
            conn.ConnectionString = driverInfo.getConnectionString()
            If (conn.ConnectionString IsNot Nothing) Then
                conn.Open()

                day = dayDropDownList.SelectedValue

                cmd = "insert into driver_availability (driverID, day, startTime, endTime) VALUES ('" & Session("driver_id") & "', '" & dayDropDownList.SelectedValue & "', '" & startHourDropDownList.SelectedValue & ":" & startMinuteDropDownList.SelectedValue & ":00 " & startAmPmDropDownList.SelectedValue & "', '" & endHourDropDownList.SelectedValue & ":" & endMinuteDropDownList.SelectedValue & ":00 " & endAmPmDropDownList.SelectedValue & "')"

                sql.CommandText = cmd
                sql.Connection = conn
                sql.ExecuteNonQuery()
            End If
           

        Catch ex As Exception
            'Response.Write(ex)
        End Try

        Response.Redirect("availability.aspx")

    End Sub
End Class
